package com.csnf.demo1.controller;

import com.csnf.demo1.pojo.Book;
import com.csnf.demo1.pojo.Result;
import com.csnf.demo1.service.BookService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class BookController {
    @Autowired
    BookService bookService;
    @RequestMapping("/findAll")
    public Result findAllBook() {
        List<Book> list = bookService.findAllBook();
        if(list != null&& list.size()>0){
            return Result.success(list);
        }else {
            return Result.error("未查询到数据");
        }
    }
    @RequestMapping("/deleteById")
    public Result deleteById(Integer id) {
        Integer i = bookService.deleteById(id);
        if (i > 0){
            return Result.success();
        }else {
            return Result.error("删除失败");
        }
    }
}
